package training.irpf.business.calc;

import java.math.BigDecimal;

import training.irpf.business.taxtable.ITabelaIrpf;

public class CalculadoraIrpf {
	private static final BigDecimal CEM = new BigDecimal("100");

	private ITabelaIrpf tabela;
	
	public CalculadoraIrpf(ITabelaIrpf tabela) {
		if (tabela == null) {
			throw new IllegalArgumentException("tabela == null");
		}
		this.tabela = tabela;
	}
	
	public BigDecimal calculaIrpf(BigDecimal base) {
		BigDecimal aliquota = tabela.buscarAliquota(base);
		BigDecimal parcela = tabela.buscarParcela(base);
		BigDecimal valor = base.multiply(aliquota);
		valor = valor.divide(CEM);
		valor = valor.subtract(parcela);
		return valor;
	}
}